<%@page import="Configurations.Application"%>
<%@page import="Configurations.ApplicationList"%>
<%@page import="java.util.Iterator"%>
<%
    /* Algorithm was obtained and modified from
     * http://roseindia.net/jsp/servlet-jsp-data-list.shtml
     */
%>
<%@page language="java" import="java.util.*" %>
<%
    session.setAttribute("displayPage", "viewTableOfApplications");
    // Redirect if this page is being displayed by itself
    if (request.getServletPath().equals("/viewTableOfApplications.jsp")) {
        System.out.println("Current Page is set to viewTableOfApplications. Redirect to index.jsp");
        response.sendRedirect("");
    }
    // Redirect to single application page if user has made a selection.
    if (request.getParameter("applicationEmail") != null) {
        session.setAttribute("displayPage", "application");
        // Store requested application email
        session.setAttribute("appRequest", request.getParameter("applicationEmail"));
        response.sendRedirect("");
    }
    //session.setAttribute("appRequest", null);
%>
<h3>Table Of Applications</h3>
<form action="">



    <%
        ApplicationList.getInstance().update();
        Iterator itr = ApplicationList.getInstance().iterator();
        while (itr.hasNext()) {


            Application app = (Application) itr.next();
            String first_name = app.getFirst_name();
            String middle_name = app.getMiddle_name();
            String last_name = app.getLast_name();
            String email_address = app.getEmail_address();
            String research_area = app.getResearch_area();
            if (research_area == "-1") {
                research_area = "N/A";
            }

            String ug_inst = app.getUg_inst();
            if (ug_inst == "-1") {
                ug_inst = "N/A";
            }

            String grad_inst = app.getGrad_inst();
            if (grad_inst == "-1") {
                grad_inst = "N/A";
            }

            String ug_GPA = "" + app.getUg_GPA();
            if (ug_GPA == "-1.0") {
                ug_GPA = "N/A";
            }

            String grad_GPA = "" + app.getGrad_GPA();
            if (grad_GPA == "-1.0") {
                grad_GPA = "N/A";
            }

            String tier = "" + app.getTier();
            if (tier.equals("-1.0")) {
                tier = "N/A";
            }

            String rating = "" + app.getRating();
            if (rating.equals("-1.0")) {
                rating = "N/A";
            }

            String ofcl_GRE_V = "" + app.getOfcl_GRE_V();
            if (ofcl_GRE_V.equals("-1")) {
                ofcl_GRE_V = "N/A";
            }

            String ofcl_GRE_Q = "" + app.getOfcl_GRE_Q();
            if (ofcl_GRE_Q.equals("-1")) {
                ofcl_GRE_Q = "N/A";
            }

            String ofcl_GRE_A = "" + app.getOfcl_GRE_A();
            if (ofcl_GRE_A.equals("-1")) {
                ofcl_GRE_A = "N/A";
            }

            String ofcl_GRE_subj = "" + app.getOfcl_GRE_subj();
            if (ofcl_GRE_subj.equals("-1")) {
                ofcl_GRE_subj = "N/A";
            }

            String ofcl_GRE_subj_name = "" + app.getOfcl_GRE_subj_name();
            if (ofcl_GRE_subj_name.equals("-1")) {
                ofcl_GRE_subj_name = "N/A";
            }

            String ofcl_TOEFL_listen = "" + app.getOfcl_TOEFL_listen();
            if (ofcl_TOEFL_listen.equals("-1")) {
                ofcl_TOEFL_listen = "N/A";
            }

            String ofcl_TOEFL_read = "" + app.getOfcl_TOEFL_read();
            if (ofcl_TOEFL_read.equals("-1")) {
                ofcl_TOEFL_read = "N/A";
            }

            String ofcl_TOEFL_speak = "" + app.getOfcl_TOEFL_speak();
            if (ofcl_TOEFL_speak.equals("-1")) {
                ofcl_TOEFL_speak = "N/A";
            }

            String ofcl_TOEFL_write = "" + app.getOfcl_TOEFL_write();
            if (ofcl_TOEFL_write.equals("-1")) {
                ofcl_TOEFL_write = "N/A";
            }

            String ofcl_TOEFL_total = "" + app.getOfcl_TOEFL_total();
            if (ofcl_TOEFL_total.equals("-1")) {
                ofcl_TOEFL_total = "N/A";
            }

    %>
    <div id="appbox">
        <table border="0" class="applicationTable">
            <tr align ="center" style="background-color:#0099cc">
                <td width="3%" style="background-color: white"><b></b></td>
                <td><b>First Name</b></td>
                <td><b>Middle Name</b></td>
                <td><b>Last Name</b></td>
                <td><b>Email Address</b></td>
                <td><b>Research Area</b></td>
                <td><b>Undergrad institution</b></td>
                <td><b>grad institution</b></td>
                <td><b>Undergrad GPA</b></td>
                <td><b>Grad GPA</b></td>
                <td><b>Tier</b></td>
                <td><b>Rating</b></td>
            </tr>

            <tr align ="center">
                <td><input type="radio" name="applicationEmail" value=<%=email_address%> checked/></td>
                <td> <%=first_name%></td>
                <td><%=middle_name%></td>
                <td><%=last_name%></td>
                <td><%=email_address%></td>
                <td><%=research_area%></td>
                <td><%=ug_inst%></td>
                <td><%=grad_inst%></td>
                <td><%=ug_GPA%></td>
                <td><%=grad_GPA%></td>
                <td><%=tier%></td> 
                <td><%=rating%></td>  

            </tr>
            <tr align="center" style="background-color:#006600">
                <td style="background-color: white"><b></b></td>
                <td><b>GRE V</b></td>
                <td><b>GRE Q</b></td>
                <td><b>GRE A</b></td>
                <td><b>GRE subj</b></td>
                <td><b>GRE subj name</b></td>          
                <td><b>TOEFL listen</b></td>
                <td><b>TOEFL read</b></td>
                <td><b>TOEFL speak</b></td>
                <td><b>TOEFL write</b></td>
                <td><b>TOEFL total</b></td>

            </tr>
            <tr align="center">
                <td style="background-color: white"><b></b></td>
                <td><%=ofcl_GRE_V%></td> 
                <td><%=ofcl_GRE_Q%></td> 
                <td><%=ofcl_GRE_A%></td> 
                <td><%=ofcl_GRE_subj%></td> 
                <td><%=ofcl_GRE_subj_name%></td> 
                <td><%=ofcl_TOEFL_total%></td> 
                <td><%=ofcl_TOEFL_listen%></td> 
                <td><%=ofcl_TOEFL_read%></td> 
                <td><%=ofcl_TOEFL_speak%></td> 
                <td><%=ofcl_TOEFL_write%></td>

            </tr>
        </table>
    </div>
    <br/>
    <%}%>
    <input type="submit" value="View Selected Application"/>
</form>